package cn.ming.wfchat.app.viewholder;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import cn.ming.wfchat.R;
import cn.ming.wfchat.app.me.activity.MyAssetsDetailsActivity;
import cn.ming.wfchat.app.me.activity.model.TransferOderDetailsActivity;
import cn.ming.wfchat.kit.annotation.EnableContextMenu;
import cn.ming.wfchat.kit.annotation.MessageContentType;
import cn.ming.wfchat.kit.conversation.ConversationFragment;
import cn.ming.wfchat.kit.conversation.message.model.UiMessage;
import cn.ming.wfchat.kit.conversation.message.viewholder.NormalMessageContentViewHolder;
import cn.wildfirechat.message.TransferMessageContent;

@MessageContentType({TransferMessageContent.class})
@EnableContextMenu
public class TransferMessageContentViewHolder extends NormalMessageContentViewHolder {

    @BindView(R.id.tv_money)
    TextView tv_money;
    @BindView(R.id.tv_title)
    TextView tv_title;
    @BindView(R.id.iv_type)
    ImageView ivType;
    @BindView(R.id.locationLinearLayout)
    LinearLayout locationLinearLayout;
    TransferMessageContent content;

    public TransferMessageContentViewHolder(ConversationFragment fragment, RecyclerView.Adapter adapter, View itemView) {
        super(fragment, adapter, itemView);
    }

    @Override
    public void onBind(UiMessage message) {
        content = (TransferMessageContent) message.message.content;
        tv_title.setText(content.getMemo());
        tv_money.setText(content.getAmount() + content.getCoinType());
        if (content.getCoinType().equals("ETH")) {
            ivType.setImageResource(R.mipmap.icon_red_eth);
        } else if (content.getCoinType().equals("RTX")) {
            ivType.setImageResource(R.mipmap.icon_red_rtx);
        } else {
            ivType.setImageResource(R.mipmap.icon_red_fj);
        }

    }

    @OnClick(R.id.locationLinearLayout)
    public void onClick(View view) {
        Intent intent = new Intent(fragment.getActivity(), TransferOderDetailsActivity.class);
        intent.putExtra("orderId", content.getId());
        intent.putExtra("coinType", content.getCoinType());
        fragment.getActivity().startActivity(intent);
    }


    @Override
    public boolean contextMenuItemFilter(UiMessage uiMessage, String tag) {
        return true;
    }
}
